<template>
  <!-- 输入框 -->
  <header class="header">
    <h1>小黑记事本</h1>
    <input
      @keyup.enter="doHandleAdd"
      v-model="todoname"
      placeholder="请输入任务"
      class="new-todo"
    />
    <button @click="doHandleAdd" class="add">添加任务</button>
  </header>
</template>

<script>
export default {
  data() {
    return {
      todoname: "",
    };
  },
  methods: {
    doHandleAdd() {
      // console.log(this.todoname);
      if (this.todoname.trim() === "") {
        alert("不能输入为空");
      }
      this.$emit("add", this.todoname);
      this.todoname = "";
    },
  },
};
</script>

<style>
</style>